#include "drumchoose.h"
#include "ui_drumchoose.h"
#include"MainWindow.h"
#include<qbitmap.h>
#include<qdebug.h>

drumChoose::drumChoose(QWidget *parent,MainWindow *p) :
    QWidget(parent),
    ui(new Ui::drumChoose)
{
    ui->setupUi(this);
    parentPtr=p;
    //窗口ui
    this->setWindowFlags(Qt::FramelessWindowHint);
    QPushButton *pb = new QPushButton(this);
    pb->setGeometry(315,745,110,35);
    pb->setStyleSheet("background-color: rgb(234, 234, 234);border-radius: 5px;");
    pb->setText(tr("comfirm"));
    pb->setFont(QFont("Bahnschrift"));
    connect(pb,SIGNAL(clicked()),this,SLOT(close()));//实现关闭

    playpb=new QPushButton(this);
    playpb->setGeometry(165,745,110,35);
    playpb->setStyleSheet("background-color: rgb(234, 234, 234);border-radius: 5px;");
    playpb->setFont(QFont("Bahnschrift"));
    playpb->setText(tr("play"));
    connect(playpb,SIGNAL(clicked()),this,SLOT(playSlot()));
    //设置播放列表
    playlist=new QMediaPlaylist;
    playlist->addMedia(QUrl("qrc:/media/sound/drumexp1.wav"));
    playlist->addMedia(QUrl("qrc:/media/sound/drumexp2.wav"));
    playlist->addMedia(QUrl("qrc:/media/sound/drumexp3.wav"));
    playlist->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
    playlist->setCurrentIndex(0);
    plr=new QMediaPlayer;
    plr->setPlaylist(playlist);

    //设置圆角窗口
    QBitmap bmp(this->size());
    bmp.fill();
    QPainter pt(&bmp);
    pt.setPen(Qt::NoPen);
    pt.setBrush(Qt::black);
    pt.drawRoundedRect(bmp.rect(),15,15);
    setMask(bmp);

    //设置list
    myList=new QListWidget(this);
    myList->setGeometry(50,75,500,200);
    myList->setIconSize(QSize(500,50));
    myList->setStyleSheet("border-radius: 5px;background-color: rgb(220, 220, 220);");
    items[0]=new QListWidgetItem("Bluebird",myList,0);
    items[1]=new QListWidgetItem("California",myList,1);
    items[2]=new QListWidgetItem("RockN'Roll",myList,2);
    connect(myList,SIGNAL(currentRowChanged(int)),this,SLOT(drumSlot()));

    //鼓组显示
    switch(parentPtr->drumset)
    {
    case 1:{
        ui->label->setStyleSheet("border-image: url(:/pic/pic/drumset1_1.jpg);");
        break;
    }
    case 2:{
        ui->label->setStyleSheet("border-image: url(:/pic/pic/drumset2.jpg);");
        break;
    }
    case 3:{
        ui->label->setStyleSheet("border-image: url(:/pic/pic/drumset3.jpg);");
        break;
    }
    default:;
    }

}

drumChoose::~drumChoose()
{
    delete ui;
}

void drumChoose::drumSlot(){
    switch(myList->currentRow())
    {
    case 0:{
        playlist->setCurrentIndex(0);
        ui->label->setStyleSheet("border-image: url(:/pic/pic/drumset1_1.jpg);");
        parentPtr->drumset=1;
        break;
    }
    case 1:{
        playlist->setCurrentIndex(1);
        ui->label->setStyleSheet("border-image: url(:/pic/pic/drumset2.jpg);");
        parentPtr->drumset=2;
        break;
    }
    case 2:{
        playlist->setCurrentIndex(2);
        ui->label->setStyleSheet("border-image: url(:/pic/pic/drumset3.jpg);");
        parentPtr->drumset=3;
        break;
    }
    default:;//点击后不显示图片，还以为是qss的问题，原来是没写break
    }

}


void drumChoose::playSlot(){
    if(plr->state()==0){

        plr->play();
        playpb->setText("pause");
        return;
    }
    if(plr->state()==1){
        plr->pause();
        playpb->setText("play");
        return;
    }
    if(plr->state()==2){
        plr->play();
        playpb->setText("pause");
        return;
    }
}
